﻿<UserControl x:Class="Passwords.Views.EditCategoriesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:utils="clr-namespace:Passwords.Utils"
             xmlns:views="clr-namespace:Passwords.Views"
             xmlns:vm="clr-namespace:Passwords.ViewModels"
             xmlns:controls="clr-namespace:Passwords.Controls"
             xmlns:models="clr-namespace:Passwords.Models"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vr="clr-namespace:Passwords.ValidationRules"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
             mc:Ignorable="d" 
             x:Name="this"
             d:DesignHeight="402" d:DesignWidth="870" Focusable="True">
    <UserControl.Resources>
        <ControlTemplate TargetType="UserControl" x:Key="template">
            <ControlTemplate.Resources>
                <ExponentialEase Exponent="5" x:Key="ease" EasingMode="EaseOut"/>
            </ControlTemplate.Resources>
            <Grid Margin="0,0,10,0"  x:Name="grid">
                <Grid.Resources>
                    <Style TargetType="RadioButton" BasedOn="{StaticResource textRadioStyle}">
                        <Setter Property="VerticalAlignment" Value="Center"/>
                    </Style>
                    <Style TargetType="Button" BasedOn="{StaticResource iconButtonStyle}"/>
                    <utils:InputScopeToIndexConverter x:Key="inputScopeToIndex"/>
                    <utils:NegConverter x:Key="negConverter"/>

                    <DataTemplate x:Key="editFieldTemplate">
                        <DataTemplate.Resources>
                            <!--<Style TargetType="Button" BasedOn="{StaticResource AccentButtonStyle}"/>-->
                        </DataTemplate.Resources>
                        <Grid x:Name="grid" Margin="0,2,3,2" >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <TextBox x:Name="nameBox" 
                                     Grid.Column="0" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}" FontSize="14" 
                                     IsEnabled="True" Margin="5,0,5,0"  />

                            <StackPanel Grid.Column="1" Orientation="Horizontal" >
                                <ComboBox x:Name="scopeBox" Width="140" Margin="0,0,4,0"  Tag="white"
                                          FontSize="14" FontWeight="Normal" IsEnabled="True"
                                          SelectedIndex="{Binding InputScope, Converter={StaticResource inputScopeToIndex}, FallbackValue=0}"  >
                                    <ComboBoxItem Content="{Binding rs.DefaultItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.PasswordItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.MemoItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.DateItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.TimeItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.TextNumberItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.DigitsItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.UrlItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.EmailItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.EMailOrAddressItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.EmailOrUserNameItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.NumberItem, Source={StaticResource locale}}"/>
                                    <ComboBoxItem Content="{Binding rs.TextItem, Source={StaticResource locale}}"/>
                                </ComboBox>
                                <Button Command="{x:Static vm:Commands.DeleteFieldCommand}" Focusable="False">
                                    <Image Source="/Passwords;component/Images/appbar.minus.rest.png" />
                                </Button>
                            </StackPanel>
                        </Grid>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}}" Value="true">
                                <Setter Property="IsEnabled" TargetName="nameBox" Value="true"/>
                                <Setter Property="IsEnabled" TargetName="scopeBox" Value="true"/>
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>

                    <DataTemplate x:Key="categoryTemplate">
                        <Grid x:Name="grid"  SnapsToDevicePixels="False">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="24"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="1" Text="{Binding Name}" FontSize="14"  VerticalAlignment="Center" 
                               TextTrimming="CharacterEllipsis" Margin="5,2,4,2"  />
                            <Border Grid.Column="0" Width="24" Height="24" SnapsToDevicePixels="true" HorizontalAlignment="Left">
                                <TextBlock Text="{Binding Passwords.Count}" FontSize="10"  Foreground="White" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Center"  />
                            </Border>
                            <Button x:Name="button" Grid.Column="2" Width="24" Height="24" Command="{x:Static vm:Commands.DeleteCategoryItemCommand}"  Visibility="Collapsed">
                                <Image Source="/Passwords;component/Images/appbar.minus.rest.png" />
                            </Button>
                        </Grid>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding Passwords.Count}" Value="0">
                                <Setter Property="Visibility" TargetName="button" Value="Visible"/>
                            </DataTrigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" Value="#16808080" TargetName="grid"/>
                            </Trigger>

                        </DataTemplate.Triggers>
                    </DataTemplate>

                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <!--Header:-->
                <Grid  Grid.Row="0" Margin="10,5,0,-5"  >
                    <Grid VerticalAlignment="Top" Margin="0,-25,20,5" TextBlock.FontSize="48" TextBlock.FontWeight="Light">
                        <TextBlock x:Name="categoriesName" Text="{Binding rs.EditCategories, Source={StaticResource locale}}">
                            <TextBlock.RenderTransform><TranslateTransform/></TextBlock.RenderTransform>
                        </TextBlock>
                        <TextBlock x:Name="editName" Text="{Binding rs.EditCategoryTitle, Source={StaticResource locale}}" Opacity="0" >
                            <TextBlock.RenderTransform><TranslateTransform/></TextBlock.RenderTransform>
                        </TextBlock>
                        <TextBlock x:Name="newName" Text="{Binding rs.NewCategoryText, Source={StaticResource locale}}" Opacity="0" Visibility="Collapsed" >
                            <TextBlock.RenderTransform><TranslateTransform/></TextBlock.RenderTransform>
                        </TextBlock>
                    </Grid>

                    <StackPanel VerticalAlignment="Top" HorizontalAlignment="Right" 
                        Margin="0,0,-4,0" Orientation="Horizontal">
                        <StackPanel.Resources>
                            <Style TargetType="RadioButton" BasedOn="{StaticResource buttonRadioStyle}"/>
                        </StackPanel.Resources>
                        <RadioButton Content="{Binding rs.PasswordsBtn, Source={StaticResource locale}}" IsChecked="{Binding AppDisplayMode, Converter={StaticResource appModeToBool}, ConverterParameter={x:Static models:AppDisplayMode.Passwords}}"/>
                        <Separator Style="{StaticResource lineSepStyle}"/>
                        <RadioButton Content="{Binding rs.SettingsBtn, Source={StaticResource locale}}" IsChecked="{Binding AppDisplayMode, Converter={StaticResource appModeToBool}, ConverterParameter={x:Static models:AppDisplayMode.Settings}}"/>
                        <Separator Style="{StaticResource lineSepStyle}"/>
                        <Button Content="{Binding rs.LogoutBtn, Source={StaticResource locale}}" Style="{StaticResource radioLikeButtonStyle}" Command="{x:Static vm:Commands.LogoutCommand}" VerticalAlignment="Center"/>
                    </StackPanel>

                </Grid>

                <!--Group Headers:-->
                <Grid Grid.Row="1"  MaxWidth="800"  >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition x:Name="CategoriesLeft" Width="{Binding Settings.CategoriesLeft, FallbackValue=170}" MinWidth="40"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <StackPanel x:Name="toolsBar"   Orientation="Horizontal" HorizontalAlignment="Right"  Margin="10,0,0,5" Grid.ColumnSpan="2" Grid.Row="0" >
                        <StackPanel.Resources>
                            <Style TargetType="Button" BasedOn="{StaticResource textButtonStyle}"/>
                        </StackPanel.Resources>
                        <Button Content="{Binding rs.AddFieldBtn, Source={StaticResource locale}}" Command="{x:Static vm:Commands.NewFieldCommand}" />
                        <Separator Style="{StaticResource lineSepStyle}"/>
                        <Button Content="{Binding rs.UpBtn, Source={StaticResource locale}}" Command="{x:Static vm:Commands.FieldUpCommand}" />
                        <Separator Style="{StaticResource lineSepStyle}"/>
                        <Button Content="{Binding rs.DownBtn, Source={StaticResource locale}}" Command="{x:Static vm:Commands.FieldDownCommand}" />
                        <!--<Button Content="DELETE CATEGORY" Command="{x:Static vm:Commands.DeleteCategoryCommand}" />
                        <Separator Style="{StaticResource lineSepStyle}"/>
                        <Button Content="NEW CATEGORY" Command="{x:Static vm:Commands.NewCategoryCommand}" />-->
                    </StackPanel>

                    <Border x:Name="categoriesHeader" Grid.Row="1" Grid.Column="0" Background="{StaticResource TransparentChromeBrush}" >
                        <TextBlock  Text="{Binding rs.EditCategories, Source={StaticResource locale}}" Style="{StaticResource headerText}"/>
                        <Border.RenderTransform>
                            <TranslateTransform x:Name="categoriesHeaderTransform"/>
                        </Border.RenderTransform>
                    </Border>


                    <Grid Grid.Row="1" Grid.Column="1" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0" />
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <!--controls:FocusContainer.IsFocused="{Binding IsCategoryFocused}"-->
                        <!--<TextBlock Grid.Row="1"  Grid.Column="0" Text="Name" FontSize="14"  VerticalAlignment="Center" TextAlignment="Right" Margin="0,0,0,4"  />-->
                        <TextBox x:Name="nameBox" Grid.Row="1" Grid.Column="1"  FontSize="14" HorizontalAlignment="Stretch" Margin="10,0,2,4" VerticalAlignment="Stretch"                                  
                                 controls:FocusContainer.UnfocusDelay="0:0:0.05" controls:FocusContainer.CanUnfocus="true"
                                 TextBlock.FontWeight="DemiBold">
                            <TextBox.Text>
                                <Binding Path="EditCategory.Name" UpdateSourceTrigger="PropertyChanged" />
                            </TextBox.Text>
                        </TextBox>
                    </Grid>

                    <!--Groups:-->
                    <ScrollViewer VerticalScrollBarVisibility="Auto" Focusable="False" Grid.Column="1"  Grid.Row="2" Margin="4,10,0,0">
                        <StackPanel>
                            <ListBox x:Name="fieldList" Focusable="False" KeyboardNavigation.TabNavigation="Once"
                                     SelectedItem="{Binding SelectedEditField}"
                                     ItemsSource="{Binding CategoryEditFields}"
                                     ItemTemplate="{StaticResource editFieldTemplate}" >
                                <ListBox.ItemContainerStyle>
                                    <Style TargetType="ListBoxItem">
                                        <Setter Property="Margin" Value="5,0,0,0"/>
                                        <Setter Property="FocusVisualStyle" Value="{StaticResource focusStyle}"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                    <Border x:Name="Border" Padding="2,1,2,1" SnapsToDevicePixels="true"  >
                                                        <Grid>
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="24"/>
                                                                <ColumnDefinition Width="*"/>
                                                            </Grid.ColumnDefinitions>
                                                            <Border x:Name="rect" Background="{DynamicResource AppMediumBrush}" Width="24" Height="24" HorizontalAlignment="Left">
                                                                <!--<Border x:Name="rect" Width="24" Height="24" HorizontalAlignment="Left">-->
                                                                <Path x:Name="path" Stroke="White" Data="M 10 8 L 14 12 L 10 16" StrokeThickness="2" VerticalAlignment="Center" HorizontalAlignment="Center" Width="24" Height="24" Visibility="Collapsed"/>
                                                            </Border>
                                                            <ContentPresenter Grid.Column="1" />
                                                        </Grid>
                                                    </Border>
                                                    <ControlTemplate.Triggers>
                                                        <!--<Trigger Property="IsMouseOver" Value="true">
                                                            <Setter Property="Opacity" Value="0.8"/>
                                                        </Trigger>-->
                                                        <Trigger Property="IsSelected" Value="true">
                                                            <Setter TargetName="Border" Property="TextBlock.FontWeight" Value="Bold"/>
                                                            <!--<Setter TargetName="path" Property="Stroke" Value="{DynamicResource AppAccentBrush}"/>-->
                                                            <Setter TargetName="path" Property="Visibility" Value="Visible"/>
                                                            <Setter TargetName="rect" Property="Background" Value="{StaticResource AppAccentBrush}"/>
                                                            <Setter TargetName="rect" Property="Effect" Value="{DynamicResource focusBitmapEffect}"/>
                                                            <Setter TargetName="Border" Property="Effect" Value="{DynamicResource focusBitmapEffect}"/>
                                                        </Trigger>
                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>

                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ListBox.ItemContainerStyle>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel IsItemsHost="True">
                                            <i:Interaction.Behaviors>
                                                <ei:FluidMoveBehavior AppliesTo="Children" Duration="0:0:0.15" EaseY="{StaticResource fluidEase}"/>
                                            </i:Interaction.Behaviors>
                                        </StackPanel>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ListBox>
                            <Button x:Name="addFieldBtn" Content="{Binding rs.EditCatAddFieldBtn, Source={StaticResource locale}}" 
                                    Template="{StaticResource addButtonTemplate}" 
                                    Width="NaN" HorizontalAlignment="Left" Margin="7,5"
                                    Command="{x:Static vm:Commands.NewFieldCommand}"/>

                            <i:Interaction.Behaviors>
                                <ei:FluidMoveBehavior AppliesTo="Children" Duration="0:0:0.15" EaseY="{StaticResource fluidEase}" FloatAbove="True"/>
                            </i:Interaction.Behaviors>

                        </StackPanel>
                    </ScrollViewer>

                    <Border x:Name="categoriesBorder" Margin="0" Grid.Row="2" Grid.Column="0" BorderThickness="0,0,1,0" BorderBrush="{DynamicResource TransparentChromeBrush}">
                        <ListBox x:Name="categoryList"  Focusable="False" 
                             ScrollViewer.CanContentScroll="False"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled" Background="Transparent"                 
                             SelectedItem="{Binding EditCategory, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}"
                             ItemsSource="{Binding Categories}"
                             ItemTemplate="{StaticResource categoryTemplate}">
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel IsItemsHost="True">
                                        <i:Interaction.Behaviors>
                                            <ei:FluidMoveBehavior AppliesTo="Children" Duration="0:0:0.15" EaseY="{StaticResource fluidEase}"/>
                                        </i:Interaction.Behaviors>
                                    </StackPanel>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                        </ListBox>
                        <Border.RenderTransform>
                                <TranslateTransform x:Name="translateCatList"/>
                        </Border.RenderTransform>
                    </Border>

                    <!--Footer:-->
                    <Border BorderThickness="0,1,0,0" Grid.Row="3" Grid.ColumnSpan="2"  BorderBrush="{DynamicResource TransparentChromeBrush}">
                        <StackPanel   Orientation="Horizontal" Margin="10,8,10,0" HorizontalAlignment="Center" >
                            <StackPanel.Resources>
                                <Style TargetType="Button" BasedOn="{StaticResource radioLikeButtonStyle}"/>
                            </StackPanel.Resources>
                            <Button Content="{Binding rs.NewCategoryBtn, Source={StaticResource locale}}" FontSize="14" Command="{x:Static vm:Commands.NewCategoryCommand}" />
                            <Separator Style="{StaticResource lineSepStyle}" />
                            <Button Content="{Binding rs.SaveBtn, Source={StaticResource locale}}" FontSize="14" Command="{x:Static vm:Commands.SaveCategoryCommand}"/>
                            <Separator Style="{StaticResource lineSepStyle}" />
                            <Button Content="{Binding rs.UndoBtn, Source={StaticResource locale}}" FontSize="14" Command="{x:Static vm:Commands.UndoCategoryCommand}"/>
                            <StackPanel.RenderTransform>
                                <TranslateTransform x:Name="footerTransform"/>
                            </StackPanel.RenderTransform>
                        </StackPanel>
                    </Border>
                    <GridSplitter Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Width="4" Background="Transparent" Focusable="False"/>
                </Grid>


            </Grid>
            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding EditCategory.IsNew}" Value="true">
                    <!--<Setter TargetName="editName" Property="Text" Value="{Binding rs.NewCategoryTitle, Source={StaticResource locale}}"/>-->
                    <Setter TargetName="editName" Property="Visibility" Value="Collapsed"/>
                    <Setter TargetName="newName" Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsCategoryModified}" Value="true">
                    <Setter TargetName="categoryList" Property="IsEnabled" Value="false"/>
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="categoriesName" Storyboard.TargetProperty="RenderTransform.X"
                                                 To="-400" Duration="0:0:0.5" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation Storyboard.TargetName="newName" Storyboard.TargetProperty="RenderTransform.X"
                                                 From="400" To="0" Duration="0:0:0.5" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation Storyboard.TargetName="categoriesName" Storyboard.TargetProperty="Opacity"
                                                 To="0" Duration="0:0:0.5" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation Storyboard.TargetName="newName" Storyboard.TargetProperty="Opacity"
                                                 To="1" Duration="0:0:0.5" EasingFunction="{StaticResource ease}"/>


                                <DoubleAnimation Storyboard.TargetName="translateCatList" Storyboard.TargetProperty="X"
                                                 To="-100" Duration="0:0:0.3" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation Storyboard.TargetName="categoriesBorder" Storyboard.TargetProperty="Opacity"
                                                 To="0" Duration="0:0:0.3" EasingFunction="{StaticResource ease}"/>

                                <DoubleAnimation Storyboard.TargetName="categoriesHeaderTransform" Storyboard.TargetProperty="X"
                                                 To="-100" Duration="0:0:0.3" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation Storyboard.TargetName="categoriesHeader" Storyboard.TargetProperty="Opacity"
                                                 To="0" Duration="0:0:0.3" EasingFunction="{StaticResource ease}"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="categoriesName" Storyboard.TargetProperty="RenderTransform.X"
                                                 To="0" Duration="0:0:0.5" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation Storyboard.TargetName="editName" Storyboard.TargetProperty="RenderTransform.X"
                                                 To="400" Duration="0:0:0.5" EasingFunction="{StaticResource ease}"/>

                                <DoubleAnimation Storyboard.TargetName="categoriesName" Storyboard.TargetProperty="Opacity"
                                                 To="1" Duration="0:0:0.5" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation Storyboard.TargetName="editName" Storyboard.TargetProperty="Opacity"
                                                 To="0" Duration="0:0:0.5" EasingFunction="{StaticResource ease}"/>


                                <DoubleAnimation Storyboard.TargetName="translateCatList" Storyboard.TargetProperty="X"
                                                 To="0" Duration="0:0:0.35" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation Storyboard.TargetName="categoriesBorder" Storyboard.TargetProperty="Opacity"
                                                 To="1" Duration="0:0:0.35" EasingFunction="{StaticResource ease}"/>

                                <DoubleAnimation Storyboard.TargetName="categoriesHeaderTransform" Storyboard.TargetProperty="X"
                                                 To="0" Duration="0:0:0.45" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation Storyboard.TargetName="categoriesHeader" Storyboard.TargetProperty="Opacity"
                                                 To="1" Duration="0:0:0.45" EasingFunction="{StaticResource ease}"/>
                            </Storyboard>

                        </BeginStoryboard>
                    </DataTrigger.ExitActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding AppDisplayMode}" Value="{x:Static models:AppDisplayMode.Categories}">
                    <Setter  Property="controls:FocusContainer.IsFocused" Value="true" TargetName="categoryList" />
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="footerTransform" Storyboard.TargetProperty="Y" From="80" To="0" EasingFunction="{StaticResource ease}" Duration="0:0:0.25"/>
                                <DoubleAnimation Storyboard.TargetName="toolsBar" Storyboard.TargetProperty="Opacity" From="0" To="1" EasingFunction="{StaticResource ease}" Duration="0:0:1"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsCategoryFocused}" Value="true">
                    <Setter Property="controls:FocusContainer.IsFocused" TargetName="nameBox" Value="true"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding EditCategory}" Value="{x:Null}">
                    <Setter Property="Visibility" Value="Collapsed" TargetName="addFieldBtn"/>
                    <Setter  Property="controls:FocusContainer.IsFocused" Value="false" TargetName="nameBox" />
                    <Setter  Property="IsEnabled" Value="false" TargetName="nameBox" />
                </DataTrigger>
            </ControlTemplate.Triggers>

        </ControlTemplate>
    </UserControl.Resources>
    <UserControl.InputBindings>
        <KeyBinding Key="Esc" Command="{x:Static vm:Commands.UndoEditCategoryCommand}" />
        <KeyBinding Key="U" Modifiers="Ctrl" Command="{x:Static vm:Commands.UndoCategoryCommand}" />
        <KeyBinding Key="Enter" Modifiers="Ctrl" Command="{x:Static vm:Commands.SaveCategoryCommand}"/>
        <KeyBinding Key="F11" Command="{x:Static vm:Commands.SaveCategoryCommand}"/>
        <KeyBinding Key="P" Modifiers="Alt" Command="{x:Static vm:Commands.PasswordsCommand}"/>
        <KeyBinding Key="N" Modifiers="Ctrl" Command="{x:Static vm:Commands.NewCategoryCommand}"/>
        <KeyBinding Key="F" Modifiers="Ctrl" Command="{x:Static vm:Commands.NewFieldCommand}"/>
        <KeyBinding Key="Del" Modifiers="Ctrl" Command="{x:Static vm:Commands.DeleteCategoryCommand}"/>
        <KeyBinding Key="X" Modifiers="Ctrl" Command="{x:Static vm:Commands.DeleteCategoryCommand}"/>
        <KeyBinding Key="Up" Modifiers="Alt"  Command="{x:Static vm:Commands.FieldUpCommand}"/>
        <KeyBinding Key="Down" Modifiers="Alt"  Command="{x:Static vm:Commands.FieldDownCommand}"/>
    </UserControl.InputBindings>
    <UserControl.Style>
        <Style TargetType="UserControl">
            <Style.Triggers>
                <DataTrigger Binding="{Binding AppDisplayMode}" Value="{x:Static models:AppDisplayMode.Categories}" >
                    <Setter Property="Template" Value="{StaticResource template}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Style>
</UserControl>
